﻿using System;
using System.Windows.Forms;
using WorkbookDesigner.Addons.SpreadsheetEditor.Model;
using System.Collections.Generic;
using WorkbookDesigner.Addons.SpreadsheetEditor.Presenter;

namespace WorkbookDesigner.Addons.SpreadsheetEditor.UI
{
    public partial class MissionView : UserControl, IMissionView
    {
        public MissionView()
        {
            InitializeComponent();
        }

        public MissionPresenter Presenter { get; set; }
        public ListView ActionViews => listViewActions;

        public OpType WorkType
        {
            get
            {
                switch (comboBoxActionSelection.SelectedIndex)
                {
                    case 0:
                        return OpType.New;
                    case 1:
                        return OpType.Edit;
                    case 2:
                        return OpType.Delete;
                    case 3:
                        return OpType.Move;
                }
                return OpType.Edit;
            }
        }
        public void ShowMissionDetail(IMission mission)
        {
            Presenter.Init(mission);
            Presenter.OnActionSelectedIndexChanged();
        }
        #region event handler

        private void MissionView_Load(object sender, EventArgs e)
        {
            comboBoxActionSelection.DataSource = Enum.GetNames(typeof(OpType));
            listViewActions.CheckBoxes = true;
            listViewActions.ShowGroups = true;
            comboBoxActionSelection.SelectedIndex = 0;
        }
        #endregion

        public void ResetListViewSize(int size = 0)
        {
            listViewActions.Items.Clear();
            listViewActions.VirtualListSize = size;
        }

        private void comboBoxSelectAction_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Presenter.Mission != null)
                Presenter.OnActionSelectedIndexChanged();
        }

        private void listViewActions_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            if (Presenter.Mission != null)
                Presenter.OnListView_RetrieveVirtualItem(e);
        }

        private void listViewActions_ItemChecked(object sender, ItemCheckedEventArgs e)
        {

        }

        private void listViewActions_ItemActivate(object sender, EventArgs e)
        {

        }

        private void listViewActions_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listViewActions_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            var item = e.Item;
        }

        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            Presenter.RefreshActionListView();
        }

        private void buttonDelete_Click(object sender, EventArgs e)
        {
            Presenter.DeleteAction();
        }


        private void buttonClearAll_Click(object sender, EventArgs e)
        {

        }

    }
}
